<template>
<div class="md-dialog-container view-main" :style="{maxHeight: styleHeight, maxWidth: styleWidth, top: styleTop}" v-show="show">
    <i class="view-close" @click.stop="hidePanel">×</i>
    <div class="md-card md-theme-default">
      <div class="md-card-media-actions">
        <div class="md-card-content">
          <img class="popoer-img" :style="imgStyle":src="pictuer.url"/>
        </div>
        <div class="md-card-actions md-alignment-right">
          <button type="button" @click="like" class="md-button md-icon-button md-theme-default">
            <div class="md-ripple">
              <div class="md-button-content"><i class="md-icon md-icon-font md-theme-default">favorite</i></div>
            </div>
          </button>
          <button type="button" class="md-button md-icon-button md-theme-default">
            <div class="md-ripple">
              <div class="md-button-content"><i class="md-icon md-icon-font md-theme-default">bookmark</i></div>
            </div>
          </button>
          <button type="button" class="md-button md-icon-button md-theme-default">
            <div class="md-ripple">
              <div class="md-button-content">
                <i class="md-icon md-icon-font md-theme-default">share</i></div>
            </div>
          </button>
        </div>
      </div>
    </div>
</div>
</template>
<script>
export default {
  name: 'ViewPictuer',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    pictuer: {
      type: Object,
      default: {
        path: '',
        filename: '',
        id: 0
      }
    }
  },
  updated() {
    this.id = this.pictuer.id
    this.positions()
  },
  created() {
    this.positions()
  },
  data() {
    return {
      scrollTop: 0,
      Imgheight: 0,
      styleHeight: 'auto',
      maxHeight: 'auto',
      styleWidth: 'auto',
      imgStyle: {
        maxHeight: 'auto',
        maxWidth: '100%'
      },
      styleTop: '0px'
    }
  },
  methods: {
    positions() {
      let windowHeight = window.innerHeight
      let picHeight = this.pictuer.height
      let defaultHeight = 32
      // 窗口留给图片 最多可占用 窗口高度 - 顶部导航栏 - 盒子边距
      let maxUseHeight = windowHeight - 64 - 64
      if (picHeight < maxUseHeight - 64) {
        console.log('需要设置高度')
        // 图片高度小于最高可占用尺寸 图片可以完整显示
        this.styleTop = (maxUseHeight - picHeight )/2 + 64 + 'px'
      } else {
        // 图片高度大于最高可占用尺寸， 图片缩放 顶部固定为 32 + 64 px
        console.log('设置为固定高度偏移 64 + 32')
        this.styleTop = '96px'
        // 对图片进行缩放处理, 最大高度为 最多可占用高度 maxUseHeight - 固定偏移
        this.imgStyle.maxHeight = maxUseHeight - 96 - 32 + 'px'
      }
    },
    like() {
      this.$emit('like')
    },
    hidePanel() {
      console.log('gengx')
      this.$emit('update:show', false);
    }
  }
}
</script>
<style lang="scss" scoped>
.view-main {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  transition: all .3s linear;
  // transform-origin: center center;
  .view-close {
    position: absolute;
    top: -1.5rem;
    right: -1.5rem;
    width: 3rem;
    height: 3rem;
    line-height: 3rem;
    z-index: 12;
    color: #666;
    font-size: 6rem;
    font-family: inherit;
    font-style: normal;
    cursor: pointer;
  }
  .md-dialog-container {
    max-height: 80vh;
  }
}
</style>
